home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / stngpasm / pure_c / include / uran / path_lib.s < prev    next >
Encoding:
Text File  |  1997-08-08  |  11.3 KB  |  368 lines

  1. ;----------------------------------------------------------------------------
  2. ;File name:    PATH_LIB.S            Revision date:    1997.08.08
  3. ;Created by:    Ulf Ronald Andersson        Creation date:    1996.02.13
  4. ;(c)1996 by:    Ulf Ronald Andersson        All rights reserved
  5. ;Released as:    FREEWARE            (commercial sale forbidden)
  6. ;----------------------------------------------------------------------------
  7. ;Purpose:    Code library for path string operations
  8. ;----------------------------------------------------------------------------
  9. ;Required header declarations:
  10. ;
  11. ;    include    "uran\STRUCT.SH"
  12. ;    include    "uran\URAn_SYS.SH"
  13. ;    include    "uran\URAn_DOS.SH"
  14. ;
  15. ;    include    "uran\Path_Lib.S"    ;in some .TEXT section
  16. ;
  17. ;----------------------------------------------------------------------------
  18. ;Subroutines:
  19. ;
  20. ; All use a0,a1 for input pointers with results in those buffers,
  21. ; leaving all registers unaltered at return.
  22. ;
  23. ;fix_path(path)          => path -> Full pathname
  24. ;get_path(path)          => path -> Full default path
  25. ;cut_path_name(path)      => path -> Full pure path without filename
  26. ;cut_path_type(path)      => path -> Full pathname without type extension
  27. ;new_path_name(path,name) => path -> Full pathname with new filename
  28. ;new_path_type(path,type) => path -> Full pathname with new type extension
  29. ;
  30. ;    all above give full absolute path, even if input is relative...
  31. ;    those below do not alter path relativity
  32. ;
  33. ;cut_name(path)        => path -> pure path without filename
  34. ;cut_type(path)        => path -> pathname without type extension
  35. ;new_name(path,name)    => path -> pathname with new filename
  36. ;new_type(path,type)    => path -> pathname with new type extension
  37. ;old_path(path,dest)    => dest -> pure path part of path
  38. ;old_name(path,name)    => name -> filename part of path
  39. ;old_type(path,type)    => type -> filetype part of path (incl period)
  40. ;
  41. ;----------------------------------------------------------------------------
  42. ;Start of:    fix_path(path_p)    => path_p -> Full pathname
  43. ;----------------------------------------------------------------------------
  44. ; path_p    -> user buffer holding pathname (possibly relative)
  45. ;----------------------------------------------------------------------------
  46. ;
  47. fix_path:
  48.     movem.l    d0-d2/a0-a4,-(sp)    ;protect entry registers
  49.     move.l    a0,a3            ;a3 -> path base
  50. ;
  51.     move.l    a3,a0            ;a0 -> path base
  52.     lea    .path_buff(pc),a1    ;a1 -> .path_buff
  53.     moveq    #127-1,d0
  54. .copy_arg:
  55.     move.b    (a0)+,(a1)+        ;copy argument to buffer
  56.     dbeq    d0,.copy_arg
  57. ;
  58.     lea    .path_buff(pc),a4    ;a4 -> arg path base
  59.     move.l    a4,a2            ;a2 -> arg path base
  60.     clr    d0
  61.     move.b    (a4)+,d0        ;d0 =  drive letter if included
  62.     beq.s    .fix_default_drive    ;get default path if none given
  63.     cmp.b    #':',(a4)+        ;colon is required after drive letter
  64.     beq.s    .fix_drive_d0
  65. .fix_default_drive:
  66.     move.l    a2,a4            ;a4 -> arg path base
  67.     gemdos    Dgetdrv            ;d0 =  default drive code
  68.     add    #'A',d0            ;d0 =  default drive letter
  69. .fix_drive_d0:
  70.     move.b    d0,(a3)+        ;store drive letter in user buffer
  71.     move.b    #':',(a3)+        ;append colon to user buffer
  72.     sub    #'A',d0
  73.     move    d0,curr_drive        ;remember curr_drive
  74. ;
  75.     cmp.b    #'\',(a4)        ;does pure path begin with backslash
  76.     beq.s    .fix_absolute
  77. .fix_relative:
  78.     move    curr_drive(pc),d0
  79.     addq    #1,d0
  80.     gemdos    Dgetpath,(a3),d0    ;append default path to user buffer
  81. .find_relation:
  82.     tst.b    (a3)+
  83.     bne.s    .find_relation
  84.     subq    #2,a3            ;back pointer to final char
  85.     cmp.b    #'\',(a3)+        ;final character backslash ?
  86.     beq.s    .append_argument    ;then append relative path directly
  87.     move.b    #'\',(a3)+        ;else append a backslash first
  88. .fix_absolute:
  89. .append_argument:
  90.     move.b    (a4)+,(a3)+        ;append argument to user buffer
  91.     bne.s    .append_argument
  92. ;
  93.     movem.l    (sp)+,d0-d2/a0-a4    ;restore entry registers
  94.     rts
  95. ;
  96. .path_buff:
  97.     ds.b    128
  98. ;
  99. ;----------------------------------------------------------------------------
  100. ;End of:    fix_path(path_p)
  101. ;----------------------------------------------------------------------------
  102. ;Start of:    get_path(path_p)    => path_p -> Full default path
  103. ;----------------------------------------------------------------------------
  104. ; path_p    -> user buffer to which path is to be copied
  105. ; curr_drive    =  static variable initially -1 (=> current default drive)
  106. ;----------------------------------------------------------------------------
  107. ;
  108. get_path:
  109.     movem.l    d0-d2/a0-a3,-(sp)    ;protect entry registers
  110.     move.l    a0,a3            ;a3 -> string destination
  111.     move    curr_drive,d0
  112.     bmi.s    .get_drive
  113.     bios    Mediach,d0
  114.     tst.l    d0
  115.     bne.s    .get_drive
  116.     move    curr_drive(pc),d0
  117.     bra.s    .put_drive
  118. ;
  119. .get_drive:
  120.     gemdos    Dgetdrv
  121. .put_drive:
  122.     move.b    d0,curr_drive
  123.     add    #'A',d0
  124.     move.l    a3,a0            ;a0 -> string destination
  125.     move.b    d0,(a0)+
  126.     move.b    #':',(a0)+
  127.     sub    #'A',d0
  128. .get_path:
  129.     addq    #1,d0
  130.     gemdos    Dgetpath,(a0),d0
  131.     move.l    a3,a0            ;a0 -> string destination
  132. .test_path:
  133.     tst.b    (a0)+
  134.     bne.s    .test_path
  135.     subq    #2,a0            ;back pointer to final char
  136.     cmp.b    #'\',(a0)+        ;final character backslash ?
  137.     beq.s    .exit
  138.     move.b    #'\',(a0)+        ;else replace terminator with backslash
  139.     clr.b    (a0)+            ;and reterminate
  140. .exit:
  141.     movem.l    (sp)+,d0-d2/a0-a3    ;restore entry registers
  142.     rts
  143. ;
  144. ;----------------------------------------------------------------------------
  145. ;End of:    get_path(path_p)
  146. ;----------------------------------------------------------------------------
  147. ;Start of:    cut_path_name(path_p)    => path_p -> Full pure path
  148. ;----------------------------------------------------------------------------
  149. ;
  150. cut_path_name:
  151.     bsr    fix_path        ;ensure full path
  152. cut_name:
  153.     movem.l    d0-d1/a0-a2,-(sp)    ;protect entry registers
  154.     move.l    a0,a2            ;a2 -> path base
  155. ;
  156.     move.l    a2,a0            ;a0 -> path base
  157.     moveq    #127-1,d0
  158. .note_slash:
  159.     move.l    a0,a1            ;a1 =  possible name start
  160. .pass_path:
  161.     move.b    (a0)+,d1
  162.     beq.s    .passed
  163.     cmp.b    #'\',d1
  164.     dbeq    d0,.pass_path
  165.     dbra    d0,.note_slash
  166. ;
  167. .passed:
  168.     clr.b    (a1)            ;reterminate path at name start
  169. ;
  170.     movem.l    (sp)+,d0-d1/a0-a2    ;restore entry registers
  171.     rts
  172. ;
  173. ;----------------------------------------------------------------------------
  174. ;End of:    cut_path_name(path_p)
  175. ;----------------------------------------------------------------------------
  176. ;Start of:    cut_path_type(path_p)    => path_p -> Full path without type
  177. ;----------------------------------------------------------------------------
  178. ;
  179. cut_path_type:
  180.     bsr    fix_path        ;ensure full path
  181. cut_type:
  182.     movem.l    d0-d1/a0-a1,-(sp)    ;protect entry registers
  183.     move.l    a0,a1            ;a1 -> path base
  184. ;
  185.     move.l    a1,a0            ;a0 -> path base
  186.     moveq    #127-1,d0
  187. .pass_path:
  188.     tst.b    (a0)+
  189.     dbeq    d0,.pass_path
  190.     subq    #1,a0            ;back pointer to terminator
  191.     moveq    #4-1,d1
  192. .pass_type:
  193.     cmpa.l    a1,a0
  194.     ble.s    .exit
  195.     move.b    -(a0),d0
  196.     cmp.b    #'\',d0
  197.     beq.s    .exit
  198.     cmp.b    #'.',d0
  199.     dbeq    d1,.pass_type
  200.     bne.s    .exit
  201.     clr.b    (a0)            ;reterminate name at extension
  202. ;
  203. .exit
  204.     movem.l    (sp)+,d0-d1/a0-a1    ;restore entry registers
  205.     rts
  206. ;
  207. ;----------------------------------------------------------------------------
  208. ;End of:    cut_path_type(path_p)
  209. ;----------------------------------------------------------------------------
  210. ;Start of:    new_path_name(path_p,name) => path_p -> path with new name
  211. ;----------------------------------------------------------------------------
  212. ;
  213. new_path_name:
  214.     bsr    fix_path        ;ensure full path
  215. new_name:
  216.     bsr    cut_name
  217.     movem.l    d0-d1/a0-a1,-(sp)    ;protect entry registers
  218. ;
  219. ;a0 -> path base
  220. ;a1 -> name base
  221. ;
  222.     moveq    #127-1,d0
  223. .pass_path:
  224.     tst.b    (a0)+
  225.     dbeq    d0,.pass_path
  226.     subq    #1,a0            ;back pointer to terminator
  227. .append_name:
  228.     move.b    (a1)+,(a0)+        ;append name to path buffer
  229.     bne.s    .append_name
  230. ;
  231.     movem.l    (sp)+,d0-d1/a0-a1    ;restore entry registers
  232.     rts
  233. ;
  234. ;----------------------------------------------------------------------------
  235. ;End of:    new_path_name(path_p,name)
  236. ;----------------------------------------------------------------------------
  237. ;Start of:    new_path_type(path_p,type) => path_p -> path with new type
  238. ;----------------------------------------------------------------------------
  239. ;
  240. new_path_type:
  241.     bsr    fix_path        ;ensure full path
  242. new_type:
  243.     bsr    cut_type
  244.     movem.l    d0-d1/a0-a1,-(sp)    ;protect entry registers
  245. ;
  246. ;a0 -> path base
  247. ;a1 -> type base
  248. ;
  249.     moveq    #127-1,d0
  250. .pass_path:
  251.     tst.b    (a0)+
  252.     dbeq    d0,.pass_path
  253.     subq    #1,a0            ;back pointer to terminator
  254. .append_type:
  255.     move.b    (a1)+,(a0)+        ;append type to path buffer
  256.     bne.s    .append_type
  257. ;
  258.     movem.l    (sp)+,d0-d1/a0-a1    ;restore entry registers
  259.     rts
  260. ;
  261. ;----------------------------------------------------------------------------
  262. ;End of:    new_path_type(path_p,type)
  263. ;----------------------------------------------------------------------------
  264. ;Start of:    old_path(path_p,dest_p) => dest_p -> old path of pathname
  265. ;----------------------------------------------------------------------------
  266. ;
  267. old_path:
  268.     movem.l    d0-d1/a0-a3,-(sp)    ;protect entry registers
  269.     move.l    a0,a2            ;a2 -> path base
  270.     move.l    a1,a3            ;a3 -> dest base
  271. ;
  272.     move.l    a2,a0            ;a0 -> path base
  273.     moveq    #127-1,d0
  274. .note_slash:
  275.     move.l    a3,a1            ;a1 =  possible dest name start
  276. .pass_path:
  277.     move.b    (a0)+,d1
  278.     move.b    d1,(a3)+
  279.     beq.s    .passed
  280.     cmp.b    #'\',d1
  281.     dbeq    d0,.pass_path
  282.     dbra    d0,.note_slash
  283. ;
  284. .passed:
  285.     clr.b    (a1)+            ;reterminate dest path at name
  286. ;
  287.     movem.l    (sp)+,d0-d1/a0-a3    ;restore entry registers
  288.     rts
  289. ;
  290. ;----------------------------------------------------------------------------
  291. ;End of:    old_path(path_p,dest_p)
  292. ;----------------------------------------------------------------------------
  293. ;Start of:    old_name(path_p,name_p) => name_p -> old name of pathname
  294. ;----------------------------------------------------------------------------
  295. ;
  296. old_name:
  297.     movem.l    d0-d1/a0-a3,-(sp)    ;protect entry registers
  298.     move.l    a0,a2            ;a2 -> path base
  299.     move.l    a1,a3            ;a3 -> name base
  300. ;
  301.     move.l    a2,a0            ;a0 -> path base
  302.     moveq    #127-1,d0
  303. .note_slash:
  304.     move.l    a0,a1            ;a1 =  possible name start
  305. .pass_path:
  306.     move.b    (a0)+,d1
  307.     beq.s    .passed
  308.     cmp.b    #'\',d1
  309.     dbeq    d0,.pass_path
  310.     dbra    d0,.note_slash
  311. ;
  312. .passed:
  313. .copy_name:
  314.     move.b    (a1)+,(a3)+
  315.     bne.s    .copy_name
  316. ;
  317.     movem.l    (sp)+,d0-d1/a0-a3    ;restore entry registers
  318.     rts
  319. ;
  320. ;----------------------------------------------------------------------------
  321. ;End of:    old_name(path_p,name)
  322. ;----------------------------------------------------------------------------
  323. ;Start of:    old_type(path_p,type_p) => type_p -> old type of pathname
  324. ;----------------------------------------------------------------------------
  325. ;
  326. old_type:
  327.     movem.l    d0-d1/a0-a2,-(sp)    ;protect entry registers
  328.     move.l    a1,a2            ;a2 -> type base
  329.     move.l    a0,a1            ;a1 -> path base
  330. ;
  331.     move.l    a1,a0            ;a0 -> path base
  332.     moveq    #127-1,d0
  333. .pass_path:
  334.     tst.b    (a0)+
  335.     dbeq    d0,.pass_path
  336.     subq    #1,a0            ;back pointer to terminator
  337.     moveq    #4-1,d1
  338. .pass_type:
  339.     cmpa.l    a1,a0
  340.     ble.s    .exit
  341.     move.b    -(a0),d0
  342.     cmp.b    #'\',d0
  343.     beq.s    .exit
  344.     cmp.b    #'.',d0
  345.     dbeq    d1,.pass_type
  346.     bne.s    .exit
  347. .copy_type:
  348.     move.b    (a0)+,(a2)+
  349.     bne.s    .copy_type
  350. ;
  351. .exit
  352.     movem.l    (sp)+,d0-d1/a0-a2    ;restore entry registers
  353.     rts
  354. ;
  355. ;----------------------------------------------------------------------------
  356. ;End of:    old_type(path_p,type)
  357. ;----------------------------------------------------------------------------
  358. ;Start of:    static data
  359. ;----------------------------------------------------------------------------
  360. ;
  361. curr_drive:    dc.w    -1
  362. ;
  363. ;----------------------------------------------------------------------------
  364. ;End of:    static data
  365. ;----------------------------------------------------------------------------
  366. ;End of file:    PATH_LIB.S
  367. ;----------------------------------------------------------------------------
  368.